/* 结构体-结构体指针
 *
 * @link: https://www.runoob.com/go/go-structures.html
 */

// 包申明
package main

// 引入包
import (
	"fmt"
)

// 定义一个书的结构
type Books struct {
	title   string
	author  string
	subject string
	book_id int
}

// 如果要访问结构体成员，需要使用点号 . 操作符
// 入口函数
func main() {
	// 声明 Book1 为 Books 类型
	var Book1 Books
	// 声明 Book2 为 Books 类型
	var Book2 Books

	// book 1 描述
	Book1.title = "Go 语言"
	Book1.author = "www.test.com"
	Book1.subject = "Go 语言教程"
	Book1.book_id = 6495407

	// book 2 描述
	Book2.title = "Python 教程"
	Book2.author = "www.test.com"
	Book2.subject = "Python 语言教程"
	Book2.book_id = 6495700

	// 打印 Book1 信息
	printBook(&Book1)

	// 打印 Book2 信息
	printBook(&Book2)
}

func printBook(book *Books) {
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book book_id : %d\n", book.book_id)
}

/*
运行结果:
Book title : Go 语言
Book author : www.test.com
Book subject : Go 语言教程
Book book_id : 6495407
Book title : Python 教程
Book author : www.test.com
Book subject : Python 语言教程
Book book_id : 6495700
*/
